package com.agile.leetcode.jvm;

/**
 * @Author KD
 * @Date 2021/1/22 8:54
 */
public class MyTest6 {
    public static void main(String[] args) {
        Singlton singlton = Singlton.getInstance();
        System.out.println(singlton.i);
        System.out.println(singlton.j);
    }
}

class Singlton {
    public static int i = 0;

    private static Singlton singlton = new Singlton();
    public static int j = 2;
    public Singlton() {
        i++; // 初始化后的值为0
        j++;// 准备阶段的值为0
        System.out.println("i="+i);
        System.out.println("j="+j);
    }

    public static Singlton getInstance() {
        return singlton;
    }
}
